// 回溯
class Solution {
public:
    vector<string> letterCombinations(string digits) {
        if (digits.size() == 0) {
            return {};
        }
        dfs(digits, 0);
        return res;
    }

private:
    vector<string> res;
    string path;
    vector<string> vec = {
        "",
        "",
        "abc",
        "def", 
        "ghi",
        "jkl",
        "mno",
        "pqrs",
        "tuv",
        "wxyz"
    };

    void dfs(string &digits, int depth) {
        if (depth == digits.size()) {
            res.push_back(path);
            return;
        }
        int num = digits[depth] - '0';
        for (int i = 0; i < vec[num].size(); ++i) {
            path.push_back(vec[num][i]);
            dfs(digits, depth + 1);
            path.pop_back();
        }
    }
};